/**
 * Create by CaoWenjian
 *
 * @copyRight: 2018
 **/
package com.bjboot.caocao.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 *@Description 界面返回结果result
 *@Author 操文健
 *@Date 2018-09-04 上午11:32
 *@Version 1.0
 **/
public class Result extends HashMap<String, Object> {
    // 传输序列化
    private static final long serialVersionUID = 1L;

    public Result() {
        put("code", 0);
        put("msg", "操作成功");
    }

    public static Result error() {
        return error(1, "操作失败");
    }

    public static Result error(String msg) {
        return error(500, msg);
    }

    public static Result error(int code, String msg) {
        Result r = new Result();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static Result ok(String msg) {
        Result r = new Result();
        r.put("msg", msg);
        return r;
    }

    public static Result ok(Map<String, Object> map) {
        Result r = new Result();
        r.putAll(map);
        return r;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Object put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
